{% extends base.html %}

{% block body_right %}
    {% include system/component/admin_nav.html %}
{% end %}

{% block body_left %}

    {% include system/component/system_css.html %}

<div class="card">
    <div class="card-title">
        <span>系统信息</span>
        <div class="float-right">
            <button class="btn btn-default" onclick="javascript:history.back();">返回</button>
        </div>
    </div>
</div>

<div class="card">
    {% for item in items %}
        <div class="settings-row">
            <div class="settings-key">{{item.name}}</div>
            <div class="settings-value">
                {% if item.link != "" %}
                    <a class="btn btn-default" href="{{_server_home}}{{item.link}}">{{item.value}}</a>
                {% else %}
                    {{item.value}}
                {% end %}
                {% if item.extra_link != "" %}
                    <a href="{{_server_home}}{{item.extra_link}}">查看详情</a>
                {% end %}
            </div>
        </div>
    {% end %}

    <div class="settings-row btn-line-height">
        <div class="settings-key">重启应用</div>
        <div class="settings-value">
            <button class="btn btn-default danger2" onclick="xnote.tmp.restart()">重启</button>
        </div>
    </div>

    <div class="settings-row btn-line-height">
        <div class="settings-key">升级系统</div>
        <div class="settings-value">
            <button class="btn btn-default danger2" onclick="xnote.tmp.upgrade()">升级</button>
        </div>
    </div>
</div>

<script type="text/javascript">
$(function () {
    var checkInterval = 500;
    var loadingIndex;

    function checkSystemStatus() {
        xnote.http.post("/system/reload?runtime_id={{runtime_id}}", function (resp) {
            console.log(resp)
            if (resp.code == "success") {
                xnote.toast("重启成功!");
                window.location.reload();                
            } else {
                setTimeout(checkSystemStatus, checkInterval)
            }
        });
    }

    function doRestart() {
        xnote.toast("重启中，请等待2-5分钟...")
        loadingIndex = layer.load(1);
        xnote.http.post("/system/reload?runtime_id={{runtime_id}}", function (resp) {
            console.log(resp);
            setTimeout(checkSystemStatus, checkInterval)
        })
    }

    xnote.tmp.restart = function () {
        xnote.confirm("确定重启吗?", function () {
            doRestart();
        })
    };

    xnote.tmp.doUpgrade = function() {
        xnote.http.post("/system/pull_code", function (resp) {
            if (resp.success) {
                doRestart();
            } else {
                xnote.alert(resp.message);
            }
        })
    }

    xnote.tmp.upgrade = function() {
        xnote.confirm("确定升级系统吗?", function () {
            xnote.tmp.doUpgrade();
        })
    }
})
</script>

{% end %}